package cn.nexd.location.collector.bean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lawrence on 2015/11/13.
 */
public class WifiSignalDeal {

    private List<Integer> recs;
    private static float[] weighted = new float[]{0.5f, 0.5f, 0.5f, 0.5f, 0.5f};


    public WifiSignalDeal() {
        if (recs == null) {
            recs = new ArrayList<Integer>();
        } else {
            recs.clear();
        }
    }

    // 向集合中添加数据
    public void add(int rec) {
        recs.add(rec);
    }


    // 获取集合值的平均值
    public int getRecAvgValue() {
        int recValue = 0;
        synchronized (recs) {
            for (int rec : recs) {
                recValue += rec;
            }
        }
        return recValue / recs.size();
    }

    public int getWeightedAvgValue() {
        int recValue = 0;
        synchronized (recs) {
            for (int i = 0, len = recs.size(); i < len; i++) {
                recValue += (recs.get(i) * weighted[i]);
            }
        }
        return recValue;
    }

    // 获取当前集合的长度
    public int getRecSize() {
        return recs.size();
    }

}